package com.verisette.ncos.service.master.bizunit;

import java.util.Date;
import java.util.Map;

import org.apache.log4j.Logger;
import org.corp.agi.common.exception.ProcessException;
import org.corp.agi.service.bean.ProcessContext;
import org.corp.agi.service.bean.UserBean;
import org.corp.agi.service.bizunit.CommonBusinessUnit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;

import com.verisette.ncos.common.ProjectConstant;
import com.verisette.ncos.persistence.dao.UserProfileManagementDAO;
import com.verisette.ncos.persistence.domain.MasterUserProfile;

public class ChangeUserLockFlagBU extends CommonBusinessUnit{

	private Logger logger = Logger.getLogger(ChangeUserLockFlagBU.class);
	
	private UserProfileManagementDAO userProfileManagementDAO;
	@Required
	@Autowired
	public void setUserProfileManagementDAO(
			UserProfileManagementDAO userProfileManagementDAO) {
		this.userProfileManagementDAO = userProfileManagementDAO;
	}

	@Override
	public void execute(ProcessContext processContext) throws ProcessException {
		
		if(logger.isInfoEnabled()) logger.info( this.getClass().getSimpleName() + ": execute" );
		
		Map<String, Object> inputMap = (Map<String, Object>)processContext.getValueObject();
		MasterUserProfile userProfile = (MasterUserProfile)inputMap.get(ProjectConstant.USER_PROFILE);
		
		UserBean user = processContext.getUserBean();
		Date currentDate = new Date();
		
		// Update UserResetPassword into MASTER_USER_PROFILE
		logger.debug("Update UserLockFlag into MASTER_USER_PROFILE.");
		
		userProfileManagementDAO.updateUserLockFlag(userProfile, user.getUsername(), currentDate);
		
	}

}
